package com.homelock.dto;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.validation.constraints.NotNull;
import java.util.Collection;

/**
 * @description 华为iot返回的通知类
 * @author chenmfa
 *         {"notifyType":"deviceDataChanged","deviceId":"25506f88-2563-4a3f-8976-ec312a5dd954",
 *         "gatewayId":"25506f88-2563-4a3f-8976-ec312a5dd954","requestId":null,
 *         "service":{"serviceId":"Message","serviceType":"Message","data":{"msgTime":1543237956,"msgType":2,
 *         "userId":"0\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"},
 *         "eventTime":"20181126T160053Z"}}
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class HuaWeiIotRecord {

    // 不验证，一般是deviceDataChanged
    private String notifyType;
    // 设备id
    private String deviceId;
    // 网关id 与设备id相同
    private String gatewayId;
    // 设备iMei
    private String imei;
    private String requestId;
    private String commandId;
    private JSONObject service;
    private JSONArray services;

    public String getNotifyType() {
        return notifyType;
    }

    public void setNotifyType(String notifyType) {
        this.notifyType = notifyType;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public String getGatewayId() {
        return gatewayId;
    }

    public void setGatewayId(String gatewayId) {
        this.gatewayId = gatewayId;
    }

    public String getRequestId() {
        return requestId;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }

    public String getCommandId() {
        return commandId;
    }

    public void setCommandId(String commandId) {
        this.commandId = commandId;
    }

    public JSONObject getService() {
        return service;
    }

    public void setService(JSONObject service) {
        this.service = service;
    }

    public JSONArray getServices() {
        return services;
    }

    public void setServices(JSONArray services) {
        this.services = services;
    }

    public String getImei() {
        return imei;
    }

    public void setImei(String imei) {
        this.imei = imei;
    }

    public String checkValidate(){
        if(StringUtils.isEmpty(this.deviceId )&& StringUtils.isEmpty(this.gatewayId )){
            return "设备iD为空";
        }
        if(StringUtils.isEmpty(this.imei)){
            return "imei为空";
        }
        if(service == null && CollectionUtils.isEmpty(services)){
            return "推送信息为空";
        }
        return "";
    }

}
